//
//  PywPayPwdModifyOldViewController.m
//  PywSdk
//
//  Created by smallwave on 16/8/12.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywPayPwdModifyOldViewController.h"
#import "UILabel+Pyw.h"
#import "UIButton+Pyw.h"
#import "PywPasswordView.h"
#import "PywCommonManager.h"
#import "PywMasonry.h"
#import "PywPayPwdModifyNewViewController.h"
#import "PywValidPhoneViewController.h"

@interface PywPayPwdModifyOldViewController ()

@property (nonatomic, strong) UILabel           *propmtLabel;       // 提示信息
@property (nonatomic, strong) PywPasswordView   *pwdView;           // 密码输入框
@property (nonatomic, strong) UIButton          *nextBtn;           // 下一步按钮
@property (nonatomic, strong) UIButton          *forgetResetPwdBtn; // 忘记密码，重置

@end

@implementation PywPayPwdModifyOldViewController
KeyBoardHelper(110)

#pragma mark - Lift Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUp];
}
- (void)viewDidDisappear:(BOOL)animated{
    [self.pwdView clearText];
}

#pragma mark - prepareUI
- (void)setUp{
    self.title = @"修改交易密码";
    self.navigationItem.rightBarButtonItem = nil;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self addSubviewAndLayoutSubviews];
}
- (void)addSubviewAndLayoutSubviews{
    [self.view addSubview:self.propmtLabel];
    
    [self.view addSubview:self.pwdView];
    self.pwdView.passwordBlock = ^(NSString *password){
        NSLog(@"%@",password);
    };
    
    [self.view addSubview:self.nextBtn];
    [self.view addSubview:self.forgetResetPwdBtn];
    
    
    __weak typeof(self) wSelf = self;
    [self.propmtLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.width.equalTo(wSelf.view.mas_width).multipliedBy(0.85);
        make.top.equalTo(wSelf.view.mas_top).offset(80);
    }];
    
    [self.pwdView mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.propmtLabel.mas_bottom).offset(20);
        make.width.equalTo(wSelf.propmtLabel.mas_width);
        make.height.equalTo(@40);
    }];
    
    [self.nextBtn mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.pwdView.mas_bottom).offset(30);
        make.width.height.equalTo(wSelf.pwdView);
    }];
    
    [self.forgetResetPwdBtn mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.top.equalTo(wSelf.nextBtn.mas_bottom).offset(10);
        make.left.equalTo(wSelf.nextBtn.mas_left);
        CGFloat width = [self changeDeviceButtonWidth:120];
        make.width.equalTo(@(width));
        make.height.equalTo(@30);
    }];
}
/**
 *  根据设备不同来确定按钮宽度
 */
- (CGFloat)changeDeviceButtonWidth:(CGFloat)btnWidth{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
    if (width < height) {
        btnWidth = (width / 320) * btnWidth;
    }else{
        btnWidth = (width / 568) * btnWidth;
    }
    return btnWidth;
}
#pragma mark - Action
- (void)nextAction{
    PywPayPwdModifyNewViewController *modifyPwdVC = [[PywPayPwdModifyNewViewController alloc] init];
    [self.navigationController pushViewController:modifyPwdVC animated:YES];
}
- (void)forgetResetPwdAction{
    PywValidPhoneViewController *checkPhoneVC = [[PywValidPhoneViewController alloc] init];
    [self.navigationController pushViewController:checkPhoneVC animated:YES];
}

#pragma mark - Lazy
- (UILabel *)propmtLabel{
    if (!_propmtLabel) {
        _propmtLabel = [UILabel labelWithText:@"请输入旧的交易密码"
                                textAlignment:NSTextAlignmentLeft
                                     fontSize:12
                                    textColor:[UIColor blackColor]];
    }
    return _propmtLabel;
}
- (PywPasswordView *)pwdView{
    if (!_pwdView) {
        _pwdView = [[PywPasswordView alloc] init];
        _pwdView.backgroundColor = [UIColor whiteColor];
        _pwdView.layer.cornerRadius = 10;
        _pwdView.layer.masksToBounds = YES;
        _pwdView.layer.borderWidth = 1;
        _pwdView.layer.borderColor = [UIColor grayColor].CGColor;
        _pwdView.elementCount = 6;
        _pwdView.elementMargin = 0;
        _pwdView.elementColor = [UIColor grayColor];
    }
    return _pwdView;
}
- (UIButton *)nextBtn{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithBackgroundColor:RGB(252, 177, 14, 1)
                                          cornerRadius:20
                                            titleColor:[UIColor whiteColor]
                                    titleLabelFontSize:18
                                                 title:@"下一步"];
        
        [_nextBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}
- (UIButton *)forgetResetPwdBtn{
    if (!_forgetResetPwdBtn) {
        CGFloat fontSize = [[PywCommonManager manager] changeDeviceTextFontSize:12];
        _forgetResetPwdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _forgetResetPwdBtn.backgroundColor = [UIColor clearColor];
        _forgetResetPwdBtn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
        [_forgetResetPwdBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_forgetResetPwdBtn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
        [_forgetResetPwdBtn setTitle:@"忘记密码，点此重置" forState:UIControlStateNormal];
        
        [_forgetResetPwdBtn addTarget:self action:@selector(forgetResetPwdAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _forgetResetPwdBtn;
}


@end
